﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2011DBProject
{
    public partial class MakeCharacter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!((Session["USER"]) == null) || !((Session["SERVER"]) == null))
            {
                lblAccount.Text = (Session["USER"]).ToString();
                lblServer.Text = (Session["SERVER"]).ToString();
            }
            else
                Response.Redirect("default.aspx?isNoSession=1");

            Label templbl = (Label)(DataList1.Controls[0].Controls[1]).FindControl("lblDLServer");
            lblServer.Text = templbl.Text;
        }

        protected void makeBtn_Click(object sender, EventArgs e)
        {
            string ac = Session["USER"].ToString();
            decimal sn = Convert.ToDecimal(Session["SERVER"]);

            DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.CHARACTERTableAdapter taCh = new DataSet1TableAdapters.CHARACTERTableAdapter();
            taCh.Connection.ConnectionString = Settings.strConnectionString;

         try{
            if (Convert.ToDecimal(taCh.ScalarQueryRowCount(ac, sn)) < 3)
            {
                DataSet1.CHARACTERRow r = ds.CHARACTER.NewCHARACTERRow();
                r.CHARACTER_NAME = txtCharacterName.Text.Trim();
                r.SEX = RadioButtonList1.SelectedValue;
                if (RadioButtonList1.SelectedValue == "M")
                    r.MODEL_ID = DropDownListM.SelectedValue;
                else if (RadioButtonList1.SelectedValue == "F")
                    r.MODEL_ID = DropDownListF.SelectedValue;
                else
                    r.MODEL_ID = "벨제";
                if (r.MODEL_ID == "보턴")
                {
                    r.TECHNIQUE = 1;
                    r.POWER = 9;
                    r.IMPACT = 1;
                    r.STRENGTH = 9;
                }
                else if (r.MODEL_ID == "샤링")
                {
                    r.TECHNIQUE = 4;
                    r.POWER = 4;
                    r.IMPACT = 8;
                    r.STRENGTH = 4;
                }
                else if (r.MODEL_ID == "엠다")
                {
                    r.TECHNIQUE = 7;
                    r.POWER = 1;
                    r.IMPACT = 11;
                    r.STRENGTH = 1;
                }
                else if (r.MODEL_ID == "벨제")
                {
                    r.TECHNIQUE = 5;
                    r.POWER = 5;
                    r.IMPACT = 5;
                    r.STRENGTH = 5;
                }
                else if (r.MODEL_ID == "제그문트")
                {
                    r.TECHNIQUE = 4;
                    r.POWER = 6;
                    r.IMPACT = 7;
                    r.STRENGTH = 3;
                }
                else if (r.MODEL_ID == "알버스")
                {
                    r.TECHNIQUE = 5;
                    r.POWER = 5;
                    r.IMPACT = 10;
                    r.STRENGTH = 2;
                }
                else
                {
                    r.TECHNIQUE = 5;
                    r.POWER = 5;
                    r.IMPACT = 5;
                    r.STRENGTH = 5;
                } 
                r.LVL = 1;
                r.HADICAP = 1;
                r.TIREDNESS = 1;
                r.EXP_TO_NEXT_LEVEL = 200;
                r.AVG_SHOTS = 0;
                r.AVG_PUTS = 0;
                r.RECENT_AVG_HANDI = 0;
                r.HOLE_IN_ONE_QTY = 0;
                r.MAX_DISTANCE = 0;
                r.NG_AMOUNT = 10000;
                r.MAX_INVENTORY_QTY = 30;
                r.EXPERIENCE = 0;
                r.SERVER_NO = Convert.ToDecimal(Session["SERVER"]);
                r.ACCOUNT_ID = (string)(Session["USER"]);
                r.TITLE_NO = 1;
                ds.CHARACTER.AddCHARACTERRow(r);
                taCh.Update(ds.CHARACTER);
                Response.Redirect("Character.aspx");
            }
            else
            {
                string script = "<script>alert('서버당 4개 이상의 캐릭터를 생성할 수 없습니다.');</script>";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "confirm", script);
            }
        }catch(Exception ex){
            string script = "<script>alert('에러번호 - #02 : 관리자에게 문의하세요.');</script>";
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "confirm", script);
        }

        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RadioButtonList1.SelectedValue.ToString() == "M")
            {
                DropDownListF.Visible = false;
                DropDownListM.Visible = true;
            }
            else
            {
                DropDownListM.Visible = false;
                DropDownListF.Visible = true;
            }
        }

        protected void RadioButtonList1_TextChanged(object sender, EventArgs e)
        {
            if (RadioButtonList1.SelectedValue.ToString() == "M")
            {
                DropDownListF.Visible = false;
                DropDownListM.Visible = true;
            }
            else
            {
                DropDownListM.Visible = false;
                DropDownListF.Visible = true;
            }
        }


        protected void btnGoLogout_onclick(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Default.aspx");
        }
        protected void btnGoServer_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Server.aspx");
        }
        protected void btnGoCharacter_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Character.aspx");
        }
    }
}


